<?php
namespace app\admin\controller;
use app\admin\model\JsTreasure;
use app\admin\model\JsPresident;
use app\admin\model\JsCustomer;
use app\admin\model\JsAdminCustomer;
use app\admin\model\JsTreasureHistory;
use app\admin\model\JsTreasureMap;
use app\admin\model\JsTreasureMission;
use app\admin\model\JsCustomerRecommends;
use app\common\util\Excel;

class Treasure extends Common{
    //藏宝前台
    public function index(){
        $this->assign('info',[]);
        return $this->fetch();
    }
    //会长列表
    public function leaderList(){
        if($_POST || !$_GET['page']){
            session('searchParam',null);
        }
        $sessionParam = session('searchParam');

        $sessionArr['uname']  = @$_POST['uname'] ? $_POST['uname'] : @$sessionParam['uname'];
        $sessionArr['tname']  = @$_POST['tname'] ? $_POST['tname'] : @$sessionParam['tname'];
        $sessionArr['start']  = @$_POST['start'] ? $_POST['start'] : @$sessionParam['start'];
        $sessionArr['end']  = @$_POST['end'] ? $_POST['end'] : @$sessionParam['end'];
        session('searchParam',$sessionArr);
        $page = @$_GET['page'] ? $_GET['page'] : 1;

        $where = [];
        $where['ApproveStateFlag'] = 4;
        $uModel = new JsCustomer();
        if($sessionArr['uname']){
            $uRes = $uModel->findData(['Username'=>$sessionArr['uname']]);
            $where['CustomerId'] = $uRes['Id'];
        }
        if($sessionArr['tname']){
            $uRes = $uModel->findData(['TrueName'=>$sessionArr['tname']]);
            $where['CustomerId'] = $uRes['Id'];
        }
        if($sessionArr['start'] && $sessionArr['end']){
            $where['CreatedOn'] = ['between',[$sessionArr['start'],$sessionArr['end'].' 23:59:59']];
        }
        $pdModel = new JsPresident();
        $resList = $pdModel->searchData($where,$page,$this->pernum,'Id desc');
        $uidArr = [];
        $cuidArr = [];
        foreach ($resList as $val){
            $uidArr[] = $val['CustomerId'];
            $cuidArr[] = $val['SecondApproveId'];
        }
        $uRes = [];
        $cuRes = [];
        if($uidArr){
            $uList = $uModel->selectData(['Id'=>['in',$uidArr]],'Id,TrueName,Username');
            foreach ($uList as $val){
                $uRes[$val['Id']]['tname'] = $val['TrueName'];
                $uRes[$val['Id']]['uname'] = $val['Username'];
            }
            $auModel = new JsAdminCustomer();
            $auList = $auModel->selectData(['uid'=>['in',$cuidArr]],'uid,name');
            foreach ($auList as $val){
                $cuRes[$val['uid']] = $val['name'];
            }
        }
        $totalNum = $pdModel->getTotalNum($where);
        $pageShow = $pdModel->paginate($this->pernum,$totalNum)->render();
        $this->assign('pageShow',$pageShow);
        $this->assign('page',$page);
        $this->assign('resList',$resList);
        $this->assign('postArr',$sessionArr);
        $this->assign('uRes',$uRes);
        $this->assign('cuRes',$cuRes);
        return $this->fetch();
    }
    //添加会长
    public function leaderAdd(){
        //设置会长
        if($_POST['setLeaderId']){
            $this->setLeader($_POST['setLeaderId']);
            return json(['code'=>0]);exit;
        }
        if($_POST || !$_GET['page']){
            session('searchParam',null);
        }
        $sessionParam = session('searchParam');

        $sessionArr['uname']  = @$_POST['uname'] ? $_POST['uname'] : @$sessionParam['uname'];
        session('searchParam',$sessionArr);
        $page = @$_GET['page'] ? $_GET['page'] : 1;

        $where = [];
        $where['IsPresident'] = 0;
        $where['Username'] = ['exp','is not null'];
        $uModel = new JsCustomer();
        if($sessionArr['uname']){
            $uRes = $uModel->findData(['Username|TrueName'=>$sessionArr['uname']]);
            $where['Id'] = $uRes['Id'];
        }
        $resList = $uModel->searchData($where,$page,$this->pernum,'Id desc');
        $ruidArr = [];
        foreach ($resList as $val){
            $ruidArr[] = $val['RecommandId'];
        }
        $ruRes = [];
        if($ruidArr){
            $ruList = $uModel->selectData(['Id'=>['in',$ruidArr]],'Id,TrueName,Username');
            foreach ($ruList as $val){
                $ruRes[$val['Id']]['tname'] = $val['TrueName'];
                $ruRes[$val['Id']]['uname'] = $val['Username'];
            }
        }
        $totalNum = $uModel->getTotalNum($where);
        $pageShow = $uModel->paginate($this->pernum,$totalNum)->render();
        $this->assign('pageShow',$pageShow);
        $this->assign('page',$page);
        $this->assign('resList',$resList);
        $this->assign('postArr',$sessionArr);
        $this->assign('ruRes',$ruRes);
        $this->view->engine->layout(false);
        return $this->fetch();
    }
    //设置会长
    private function setLeader($uid){
        $uModel = new JsCustomer();
        $uRes = $uModel->findData(['Id'=>$uid]);
        if($uRes['IsPresident'] == 1){
            return;
        }
        $uModel->editData(['Id'=>$uid],['IsPresident'=>1]);
        $tbModel = new JsTreasure();
        $tbAmount = $tbModel->sumData(['CustomerId'=>$uid],'Amount');
        $pdModel = new JsPresident();
        $data = [];
        $timeNow = date('Y-m-d H:i:s');
        $data['CustomerId'] = $uid;
        $data['ApproveStateFlag'] = 4;
        $data['SecondApproveId'] = $this->user_id;
        $data['SecondApprovedOn'] = $timeNow;
        $data['CreatedOn'] = $timeNow;
        $data['PersonalTreasure'] = $tbAmount ? $tbAmount : 0;
        $data['TeamTreasure'] = $uRes['Treasure'];
        $data['TeamNum'] = $uRes['TeamNum'];
        $pdModel->addData($data);
    }
    //会长审核列表
    public function leaderCheckList(){
        if($_POST || !$_GET['page']){
            session('searchParam',null);
        }
        $sessionParam = session('searchParam');

        $sessionArr['uname']  = @$_POST['uname'] ? $_POST['uname'] : @$sessionParam['uname'];
        $sessionArr['tname']  = @$_POST['tname'] ? $_POST['tname'] : @$sessionParam['tname'];
        $sessionArr['start']  = @$_POST['start'] ? $_POST['start'] : @$sessionParam['start'];
        $sessionArr['end']  = @$_POST['end'] ? $_POST['end'] : @$sessionParam['end'];
        session('searchParam',$sessionArr);
        $page = @$_GET['page'] ? $_GET['page'] : 1;

        $where = [];
        $where['ApproveStateFlag'] = 1;
        $uModel = new JsCustomer();
        if($sessionArr['uname']){
            $uRes = $uModel->findData(['Username'=>$sessionArr['uname']]);
            $where['CustomerId'] = $uRes['Id'];
        }
        if($sessionArr['tname']){
            $uRes = $uModel->findData(['TrueName'=>$sessionArr['tname']]);
            $where['CustomerId'] = $uRes['Id'];
        }
        if($sessionArr['start'] && $sessionArr['end']){
            $where['CreatedOn'] = ['between',[$sessionArr['start'],$sessionArr['end'].' 23:59:59']];
        }
        $pdModel = new JsPresident();
        $resList = $pdModel->searchData($where,$page,$this->pernum,'Id desc');
        $uidArr = [];
        foreach ($resList as $val){
            $uidArr[] = $val['CustomerId'];
        }
        $uRes = [];
        if($uidArr){
            $uList = $uModel->selectData(['Id'=>['in',$uidArr]],'Id,TrueName,Username');
            foreach ($uList as $val){
                $uRes[$val['Id']]['tname'] = $val['TrueName'];
                $uRes[$val['Id']]['uname'] = $val['Username'];
            }
        }
        $totalNum = $pdModel->getTotalNum($where);
        $pageShow = $pdModel->paginate($this->pernum,$totalNum)->render();
        $this->assign('pageShow',$pageShow);
        $this->assign('page',$page);
        $this->assign('resList',$resList);
        $this->assign('postArr',$sessionArr);
        $this->assign('uRes',$uRes);
        return $this->fetch();
    }
    //审核会长
    public function leaderCheck(){
        $pdModel = new JsPresident();
        if($_POST){
            $pdRes = $pdModel->findData(['Id'=>$_POST['id']]);
            if($_POST['state'] == 4){
                $uModel = new JsCustomer();
                $uModel->editData(['Id'=>$pdRes['CustomerId']],['IsPresident'=>1]);
            }
            $pdModel->editData(['Id'=>$_POST['id']],['ApproveStateFlag'=>$_POST['state'],'SecondApproveId'=>$this->user_id,'SecondApproveMemo'=>$_POST['secmemo'],'SecondApprovedOn'=>date('Y-m-d H:i:s')]);
            $this->redirect('/admin/treasure/leaderCheckList?page='.$_POST['page']);
        }
        $id = $_GET['id'];
        $pdRes = $pdModel->findData(['Id'=>$id]);
        $uModel = new JsCustomer();
        $uRes = $uModel->findData(['Id'=>$pdRes['CustomerId']]);
        $puRes = $uModel->findData(['Id'=>$pdRes['FirstApproveId']]);
        $this->assign('pdRes',$pdRes);
        $this->assign('uRes',$uRes);
        $this->assign('puRes',$puRes);
        $this->assign('page',$_GET['page']);
        return $this->fetch();
    }
    //藏宝记录
    public function treasureRecord(){
        if($_POST || !$_GET['page']){
            session('searchParam',null);
        }
        $sessionParam = session('searchParam');
        $sessionArr['uname']  = @$_POST['uname'] ? $_POST['uname'] : @$sessionParam['uname'];
        $sessionArr['tname']  = @$_POST['tname'] ? $_POST['tname'] : @$sessionParam['tname'];
        $sessionArr['start']  = @$_POST['start'] ? $_POST['start'] : @$sessionParam['start'];
        $sessionArr['end']  = @$_POST['end'] ? $_POST['end'] : @$sessionParam['end'];
        session('searchParam',$sessionArr);
        $page = @$_GET['page'] ? $_GET['page'] : 1;

        $where = [];
        $uModel = new JsCustomer();
        if($sessionArr['uname']){
            $uRes = $uModel->findData(['Username'=>$sessionArr['uname']]);
            $where['CustomerId'] = $uRes['Id'];
        }
        if($sessionArr['tname']){
            $uRes = $uModel->findData(['TrueName'=>$sessionArr['tname']]);
            $where['CustomerId'] = $uRes['Id'];
        }
        if($sessionArr['start'] && $sessionArr['end']){
            $where['CreateOn'] = ['between',[$sessionArr['start'],$sessionArr['end'].' 23:59:59']];
        }
        $tbModel = new JsTreasure();
        $resList = $tbModel->searchData($where,$page,$this->pernum,'Id desc');
        $uidArr = [];
        foreach ($resList as $val){
            $uidArr[] = $val['CustomerId'];
        }
        $uRes = [];
        if($uidArr){
            $uList = $uModel->selectData(['Id'=>['in',$uidArr]],'Id,TrueName,Username');
            foreach ($uList as $val){
                $uRes[$val['Id']]['tname'] = $val['TrueName'];
                $uRes[$val['Id']]['uname'] = $val['Username'];
            }
        }
        $totalNum = $tbModel->getTotalNum($where);
        $pageShow = $tbModel->paginate($this->pernum,$totalNum)->render();
        $this->assign('pageShow',$pageShow);
        $this->assign('page',$page);
        $this->assign('resList',$resList);
        $this->assign('postArr',$sessionArr);
        $this->assign('uRes',$uRes);
        $this->assign('boxType',['1'=>'通用型','2'=>'经济型','3'=>'创业型','4'=>'企业型']);
        return $this->fetch();
    }
    //宝图明细
    public function mapRecord(){
        $id = $_GET['id'];
        $page = @$_GET['page'] ? $_GET['page'] : 1;
        $tmiModel = new JsTreasureMission();
        $tmModel = new JsTreasureMap();
        $tmList = $tmModel->selectData(['TreasureId'=>$id]);
        $tmRes = [];
        foreach ($tmList as $val){
            $arr = [];
            $arr['num'] = $val['ChangeNum'];
            $arr['unlocknum'] = $val['UnlockNum'];
            $arr['completenum'] = $val['CompleteNum'];
            $arr['memo'] = $val['Memo'];
            $arr['update'] = $val['CreatedOn'];
            $arr['time'] = strtotime($val['CreatedOn']);
            $arr['statue'] = '完成';
            $arr['isshop'] = 0;
            $tmRes[] = $arr;
        }
        $tmiList = $tmiModel->selectData(['TreasureId'=>$id,'MissionId'=>1,'State'=>['in',[0,10,80]]]);
        $tmiRes = [];
        foreach ($tmiList as $val){
            $arr = [];
            $arr['num'] = 1;
            $arr['memo'] = '商城购物';
            $arr['update'] = $val['CreateOn'];
            $arr['time'] = strtotime($val['CreateOn']);
            $arr['statue'] = $val['State']==80 ? '退货' : '进行中';
            $arr['isshop'] = 1;
            $tmiRes[] = $arr;
        }
        $res = array_merge($tmRes,$tmiRes);
        $times = array();
        foreach ($res as $val) {
            $times[] = $val['time'];
        }
        array_multisort($times, SORT_ASC, $res);
        $unlocknum = $completenum = 0;
        foreach ($res as &$val){
            if($val['isshop'] == 0){
                $unlocknum = $val['unlocknum'];
                $completenum = $val['completenum'];
            }
            if($val['isshop'] == 1){
                $val['unlocknum'] = $unlocknum;
                $val['completenum'] = $completenum;
            }
        }
        array_multisort($times, SORT_DESC, $res);

        $totalNum = count($res);
        $start = ($page-1)*$this->pernum;
        $resList = array_slice($res,$start,$this->pernum);

        $pageShow = $tmModel->paginate($this->pernum,$totalNum,['query'=>['id'=>$id]])->render();
        $this->assign('pageShow',$pageShow);
        $this->assign('resList',$resList);
        $this->view->engine->layout(false);
        return $this->fetch();
    }
    //藏宝排行榜
    public function treasureRank(){
        if($_POST || !$_GET['page']){
            session('searchParam',null);
        }
        $sessionParam = session('searchParam');
        if($_GET['export']){
            $_POST = $_GET;
        }
        $sessionArr['uname']  = @$_POST['uname'] ? $_POST['uname'] : @$sessionParam['uname'];
        $sessionArr['tname']  = @$_POST['tname'] ? $_POST['tname'] : @$sessionParam['tname'];
        $sessionArr['sort']  = @$_POST['sort'] ? $_POST['sort'] : @$sessionParam['sort'];
        $sessionArr['start']  = @$_POST['start'] ? $_POST['start'] : @$sessionParam['start'];
        $sessionArr['end']  = @$_POST['end'] ? $_POST['end'] : @$sessionParam['end'];
        session('searchParam',$sessionArr);
        $page = @$_GET['page'] ? $_GET['page'] : 1;

        $uModel = new JsCustomer();
        $thModel = new JsTreasureHistory();
        $uid = 0;
        if($sessionArr['uname']){
            $uRes = $uModel->findData(['Username'=>$sessionArr['uname']]);
            $uid = $uRes['Id'];
        }
        if($sessionArr['tname']){
            $uRes = $uModel->findData(['TrueName'=>$sessionArr['tname']]);
            $uid = $uRes['Id'];
        }
        $sort = $sessionArr['sort'] ? $sessionArr['sort'] : 1;
        $startNum = ($page-1)*$this->pernum;
        $where = '';
        $pageShow = '';
        $resList = [];
        if($sessionArr['start'] && $sessionArr['end']){
            $end = $sessionArr['end'].' 23:59:59';
            if($uid){
                $where = "and CustomerId={$uid} ";
            }
            //累加
            $tbList = $uModel->queryData("SELECT CustomerId,Amount FROM treasure WHERE CreateOn>='{$sessionArr['start']}' AND CreateOn<='{$end}' {$where}");
            $tdList = $uModel->queryData("select CustomerId,Treasure from treasuredaily WHERE CreatedOn>='{$sessionArr['start']}' AND CreatedOn<='{$end}' {$where}");
            $tbRes = [];
            foreach ($tbList as $val){
                $tbRes[$val['CustomerId']]['amount'] += $val['Amount'];
                $tbRes[$val['CustomerId']]['uid'] = $val['CustomerId'];
            }
            $tdRes = [];
            foreach ($tdList as $val){
                $tdRes[$val['CustomerId']]['treasure'] += $val['Treasure'];
                $tdRes[$val['CustomerId']]['uid'] = $val['CustomerId'];
            }
            $uidArr = [];
            if($sort == 1) { //个人藏宝总额排序
                $totalNum = count($tbRes);
                $amount = array();
                foreach ($tbRes as $val){
                    $amount[] = $val['amount'];
                }
                array_multisort($amount, SORT_DESC, $tbRes);
                if($_GET['export']) {
                    $slRes = $tbRes;
                }else{
                    $slRes = array_slice($tbRes, $startNum, $this->pernum);
                }
                foreach ($slRes as &$aval){
                    $aval['treasure'] = $tdRes[$aval['uid']]['treasure'];
                    $uidArr[] = $aval['uid'];
                }
            }else{
                $totalNum = count($tdRes);
                $amount = array();
                foreach ($tdRes as $val){
                    $amount[] = $val['treasure'];
                }
                array_multisort($amount, SORT_DESC, $tdRes);
                if($_GET['export']) {
                    $slRes = $tbRes;
                }else{
                    $slRes = array_slice($tdRes, $startNum, $this->pernum);
                }
                foreach ($slRes as &$bval){
                    $bval['amount'] = $tbRes[$bval['uid']]['amount'];
                    $uidArr[] = $bval['uid'];
                }
            }
            if(!$_GET['export']) {
                $pageShow = $uModel->paginate($this->pernum, $totalNum)->render();
            }
            if($uidArr){
                $uList = $uModel->selectData(['Id'=>['in',$uidArr]],['Id','Username','TrueName','TeamNum','Treasure']);
            }
            $uRes = [];
            foreach ($uList as $val){
                $uRes[$val['Id']] = $val;
            }
            foreach ($slRes as $val){
                $arr = [];
                $arr['uname'] = $uRes[$val['uid']]['Username'];
                $arr['tname'] = $uRes[$val['uid']]['TrueName'];
                $arr['hideamount'] = $val['amount'];
                $arr['totalamount'] = $val['treasure']>$val['amount'] ? $val['treasure'] : $val['amount'];
                $arr['teamnum'] = $uRes[$val['uid']]['TeamNum'];
                $arr['uid'] = $val['uid'];
                $resList[] = $arr;
            }
        }else{
            //所有
            if($sort == 1){ //个人藏宝总额排序
                if($uid){
                    $where = " where CustomerId={$uid} ";
                }
                //导出
                if($_GET['export']){
                    $thList = $uModel->queryData("select CustomerId,HideAmount from treasurehistory {$where} order by HideAmount DESC");
                }else{
                    $thList = $uModel->queryData("select CustomerId,HideAmount from treasurehistory {$where} order by HideAmount DESC limit {$startNum},{$this->pernum}");
                    $totalNum = $uModel->queryData("select count(1) as num from treasurehistory {$where}");
                    $pageShow = $uModel->paginate($this->pernum,$totalNum[0]['num'])->render();
                }
                $uidArr = [];
                foreach ($thList as $val){
                    $uidArr[] = $val['CustomerId'];
                }
                if($uidArr){
                    $uList = $uModel->selectData(['Id'=>['in',$uidArr]],['Id','Username','TrueName','TeamNum','Treasure']);
                }
                $uRes = [];
                foreach ($uList as $val){
                    $uRes[$val['Id']] = $val;
                }
                foreach ($thList as $val){
                    $arr = [];
                    $arr['uname'] = $uRes[$val['CustomerId']]['Username'];
                    $arr['tname'] = $uRes[$val['CustomerId']]['TrueName'];
                    $arr['hideamount'] = $val['HideAmount'];
                    $arr['totalamount'] = $uRes[$val['CustomerId']]['Treasure'];
                    $arr['teamnum'] = $uRes[$val['CustomerId']]['TeamNum'];
                    $arr['uid'] = $val['CustomerId'];
                    $resList[] = $arr;
                }
            }else{//累计业绩排序
                if($uid){
                    $where = " where Id={$uid} ";
                }
                //导出
                if($_GET['export']){
                    $uRes = $uModel->queryData("select Id,Username,TrueName,TeamNum,Treasure from customer {$where} order by Treasure DESC");
                }else{
                    $uRes = $uModel->queryData("select Id,Username,TrueName,TeamNum,Treasure from customer {$where} order by Treasure DESC limit {$startNum},{$this->pernum}");
                    $totalNum = $uModel->queryData("select count(1) as num from customer {$where}");
                    $pageShow = $uModel->paginate($this->pernum,$totalNum[0]['num'])->render();
                }
                $uidArr = [];
                foreach ($uRes as $val){
                    $uidArr[] = $val['Id'];
                }
                if($uidArr){
                    $thList = $thModel->selectData(['CustomerId'=>['in',$uidArr]],['CustomerId','HideAmount']);
                }
                $thRes = [];
                foreach ($thList as $val){
                    $thRes[$val['CustomerId']] = $val['HideAmount'];
                }
                foreach ($uRes as $val){
                    $arr = [];
                    $arr['uname'] = $val['Username'];
                    $arr['tname'] = $val['TrueName'];
                    $arr['hideamount'] = $thRes[$val['Id']]['HideAmount'];
                    $arr['totalamount'] = $val['Treasure'];
                    $arr['teamnum'] = $val['TeamNum'];
                    $arr['uid'] = $val['Id'];
                    $resList[] = $arr;
                }
            }
        }
        if($_GET['export']){
            $this->exportTreasureRank($resList);return;
        }
        $this->assign('resList',$resList);
        $this->assign('page',$page);
        $this->assign('pageShow',$pageShow);
        $this->assign('postArr',$sessionArr);
        return $this->fetch();
    }
    //导出藏宝排行数据
    public function exportTreasureRank($resList){
        $data = [];
        $arr = ['用户名','真实姓名','个人藏宝','累计业绩'];
        $data[] = $arr;
        foreach($resList as $vo){
            $arr = [$vo['uname'],$vo['tname'],$vo['hideamount'],$vo['totalamount']];
            $data[] = $arr;
        }
        $excel = new Excel();
        $file = $excel->createXls($data,'treasureRank-'.time());
        $this->fileDownLoad($file);
    }
    //团队成员列表
    public function teamUser(){
        $id = $_GET['id'];
        $page = @$_GET['page'] ? $_GET['page'] : 1;

        $sessionArr['uname']  = @$_POST['uname'] ? $_POST['uname'] : @$sessionParam['uname'];
        $sessionArr['tname']  = @$_POST['tname'] ? $_POST['tname'] : @$sessionParam['tname'];
        session('searchParam',$sessionArr);
        $uModel = new JsCustomer();
        $uid = 0;
        if($sessionArr['uname']){
            $uRes = $uModel->findData(['Username'=>$sessionArr['uname']]);
            $uid = $uRes['Id'];
        }
        if($sessionArr['tname']){
            $uRes = $uModel->findData(['TrueName'=>$sessionArr['tname']]);
            $uid = $uRes['Id'];
        }
        $startNum = ($page-1)*$this->pernum;

        $leaderRes = $uModel->findData(['id'=>$id]);
        $urModel = new JsCustomerRecommends();
        $pidFormat = '%,'.$id.',%';
        $urList = $urModel->selectData(['pids'=>['like',$pidFormat]],'uid');
        $urIdArr = [-1];
        foreach ($urList as $val){
            $urIdArr[] = $val['uid'];
        }
        $urIdStr = implode(',',$urIdArr);
        $where = " where a.Id in ({$urIdStr}) ";
        if($uid){
            $where .= " and a.Id={$uid} ";
        }
        $thList = $uModel->queryData("select a.Username,a.TrueName,a.TeamNum,a.Treasure,b.HideAmount from customer a Left Join treasurehistory b on a.Id=b.CustomerId {$where} order by b.HideAmount DESC limit {$startNum},{$this->pernum}");

        $totalNum = $uModel->queryData("select count(1) as num from customer a {$where}");
        $pageShow = $uModel->paginate($this->pernum,$totalNum[0]['num'],['query'=>['id'=>$id]])->render();
        $resList = [];
        foreach ($thList as $val){
            $arr = [];
            $arr['uname'] = $val['Username'];
            $arr['tname'] = $val['TrueName'];
            $arr['hideamount'] = $val['HideAmount'];
            $arr['totalamount'] = $val['Treasure'];
            $arr['teamnum'] = $val['TeamNum'];
            $resList[] = $arr;
        }
        $this->assign('pageShow',$pageShow);
        $this->assign('page',$page);
        $this->assign('resList',$resList);
        $this->assign('postArr',$sessionArr);
        $this->assign('leaderRes',$leaderRes);
        $this->assign('id',$id);
        $this->view->engine->layout(false);
        return $this->fetch();
    }
}